package io.jee.runshan.handler;

import io.jee.runshan.domain.KeywordAsk;
import io.jee.runshan.domain.remote.weixin.InputMessage;
import io.jee.runshan.domain.remote.weixin.OutputTextMessage;
import io.jee.runshan.service.IKeywordAskService;
import io.jee.runshan.utils.SpringHolder;
import io.jee.runshan.utils.WeixinConstant;

import java.util.List;

/**
 * 固定问题匹配处理
 * @author qinling.zhu
 *
 */
public class WeixinReceiverAskHandler {
	
	private IKeywordAskService keywordAskService = SpringHolder.getBean(IKeywordAskService.class);
	
	public String excute(InputMessage inputMsg) throws Exception {
		OutputTextMessage outputMsg = new OutputTextMessage();
		List<KeywordAsk> list = keywordAskService.list("type", KeywordAsk.TYPE_FIXED);
		StringBuffer msg = new StringBuffer("欢迎使用咨询服务！\n");
		for (KeywordAsk keywordAsk : list) {
			msg.append("回复").append(keywordAsk.getKeyword()).append("：").append(keywordAsk.getTitle()).append("\n");
		}
		msg.append("感谢您对我们的支持，谢谢！");
		outputMsg.setContent(msg.toString());
		return WeixinConstant.genMessage(outputMsg, inputMsg);
	}
	
}
